package com.controller;

import com.pojo.Consumer;
import com.pojo.SalesOrder;
import com.pojo.requestjson.AddSalesProductDetailRequestJson;
import com.service.iter.ISaleOrderService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Dumeng
 * @description TODO
 * @date 2023/7/4 16:39
 */
@RestController
@RequestMapping("/checkout")
public class CheckOutController {
    private final ISaleOrderService saleOrderService;

    @Autowired
    public CheckOutController(ISaleOrderService saleOrderService) {
        this.saleOrderService = saleOrderService;
    }

    /**
     * 结帐
     *
     * @param requestJson 请求json
     * @return {@link Res}
     */
    @PostMapping("/payOrder")
    public Res payOrder(@RequestBody AddSalesProductDetailRequestJson requestJson) {
        return saleOrderService.addSaleOrder(requestJson);
    }

    /**
     * 查询支付状态
     *
     * @param salesOrderId 订单号
     * @return {@link Res}
     */
    @GetMapping("/queryOrder")
    public Res queryOrder(Long salesOrderId) {
        return saleOrderService.updateStatus(salesOrderId);
    }


    @GetMapping("/QueryByCustomPhone")
    public List<SalesOrder> QueryByCustomPhone(String customPhone) {
        return saleOrderService.QueryByCustomPhone(customPhone);
    }

}
